<?php

namespace App\Listeners;

use Illuminate\Auth\Events\Login;
use Encore\Admin\Auth\Database\Administrator;

class UpdateLastLoginTime
{
    /**
     * Create the event listener.
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     */
    public function handle(Login $event): void
    {
        $user = $event->user;
        if ($user instanceof Administrator) {
            $user->last_login_at = now();
            $user->save();
        }
    }
}
